package com.ruoyi.web.controller.system;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysCheck;
import com.ruoyi.system.service.ISysCheckService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 公告 信息操作处理
 *
 * @author ruoyi
 */
@RestController
@RequestMapping("/system/check")
public class SysCheckController extends BaseController {
    @Autowired
    private ISysCheckService checkService;

    /**
     * 获取检查费用项目列表
     */
    @PreAuthorize("@ss.hasPermi('system:check:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysCheck check) {
        startPage();
        List<SysCheck> list = checkService.selectCheckList(check);
        return getDataTable(list);
    }

    /**
     * 新增检查费用项目
     */
    @PreAuthorize("@ss.hasPermi('system:check:add')")
    @Log(title = "检查费用项目", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody SysCheck check) {
        check.setUpdateBy(getUsername());
        System.out.println(check);
        return toAjax(checkService.insertCheck(check));
    }

    /**
     * 根据通知公告编号获取详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:check:query')")
    @GetMapping(value = "/{checkId}")
    public AjaxResult getInfo(@PathVariable Long checkId) {
        return success(checkService.selectCheckById(checkId));
    }

    /**
     * 修改检查费用
     */
    @PreAuthorize("@ss.hasPermi('system:check:edit')")
    @Log(title = "检查费用", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody SysCheck check) {
        check.setUpdateBy(getUsername());
        return toAjax(checkService.updateCheck(check));
    }

    /**
     * 删除通知公告
     */
    @PreAuthorize("@ss.hasPermi('system:check:remove')")
    @Log(title = "通知公告", businessType = BusinessType.DELETE)
    @DeleteMapping("/{checkIds}")
    public AjaxResult remove(@PathVariable Long[] checkIds) {
        return toAjax(checkService.deleteCheckByIds(checkIds));
    }
}
